<template>
	<view class="content" :style="{ backgroundImage: 'url(' + sharedata.url + ')' }">
		<view class="footer">
			<view class="icon">
				<!-- #ifdef APP-PLUS -->
				<view class="" @click="toWeixin">
					<image style='width:120rpx;height:120rpx;' :src="iconurl + '/static/newImg/weChat friends.png'"
						mode="aspectFit"></image>
					<text>微信好友</text>
				</view>
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<button type="default" open-type="share" class="mysharebtn">
					<view class="">
						<image :src="iconurl + '/static/newImg/weChat friends.png'" mode="aspectFit"></image>
						<text style="line-height: 28rpx;">微信好友</text>
					</view>
				</button>
				<!-- #endif -->

				<view class="" @tap="saveimg">
					<image :src="iconurl + '/static/newImg/savePicture.png'" mode="aspectFit"></image>
					<text>保存图片</text>
				</view>

			</view>
		</view>
		<u-popup mode="center" v-model="box_Status" border-radius="20">
			<view class="share_box">
				<view class="title">
					恭喜获得
				</view>
				<image class="picurl" :src="getdata.list.prize_icon"></image>
				<view class="name">
					{{ getdata.list.prize_name }}
				</view>
				<view class="share_btn">
					<view class="left flex-c-c" @tap="box_Status = false">
						放入仓库
					</view>
					<view class="right flex-c-c" @tap="opensharemh">
						立即开箱
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
// import uQrCode from "@/common/uqrcode.js"
export default {
	data() {
		return {
			// 二维码链接
			// codeLink: "",
			box_Status: false,
			sharedata: {
				url: "",
				share_url: ""
			},
			screenHeight: "",
			getdata: {
				status: "",
				list: {}
			},
			iconurl: this.$configs.urls,
		};
	},
	onShow() {
		this.getlist()
	},
	onShareAppMessage: function (res) {
		console.log(res);
        if (res.from === 'button') { // 来自页面内分享按钮
            console.log(res.target,"54154141")
        }
        return {
            path: '/pages/index/redouble',
            imageUrl: this.sharedata.url,
        }
	},
	methods: {

		opensharemh() {
			uni.navigateTo({
				url: "/orderPage/index/kaihe?id=" + this.getdata.list.id
			})
		},
		// 分享给微信好友
		toWeixin() {
			var that = this
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneSession',
				type: 0,
				imageUrl: 'https://mh.qingfentool.vip/upload/image/20230529/fb2e040f5177508cb28295f52b25c021.png',
				href: that.sharedata.url,
				title: "大王赏下载",
				success: res => {
					uni.showToast({
						title: '分享成功',
						icon: 'success',
						duration: 600
					});
					that.getsharemh()
				}
			});
		},
		// 分享到朋友圈
		toFriend() {

			var that = this
			uni.share({
				provider: 'weixin',
				scene: 'WXSenceTimeline',
				type: 0,
				href: that.sharedata.url,
				title: "分享",
				success: function (res) {
					////console.log(res,"分享")
					uni.showToast({
						title: '分享成功',
						icon: 'success',
						duration: 600
					});
					that.getsharemh()
				},
				fail: function () { }
			});
		},
		getsharemh() {
			this.$Request.get(this.$api.index.eventNotify).then(res => {

				////console.log(res,"图片")
				this.getdata = res.data;
				if (this.getdata.status == 1) {
					this.box_Status = true;
				} else if (this.getdata.status == 2) {
					this.box_Status = false;
				}
			});
		},
		getlist() {
			let data = {
				is_wechat_x: 1
			}
			// #ifdef MP-WEIXIN
			data.is_wechat_x = 1
			// #endif
			this.$Request.get(this.$api.index.share, data).then(res => {
				uni.setStorageSync('url', res.data.url)
				this.sharedata = res.data;
				uQrCode.make({
					canvasId: 'qrcode',
					componentInstance: this,
					text: res.data.share_url,
					size: 80,
					margin: 0,
					backgroundColor: '#ffffff',
					foregroundColor: '#000000',
					fileType: 'jpg',
					errorCorrectLevel: uQrCode.errorCorrectLevel.H,
					success: res => { }
				})
				// this.codeLink = 
			});
		},
		// 二维码
		// QuickMark(){

		// },
		// setClipboard() {
		// 	uni.setClipboardData({
		// 		data: this.sharedata.share_url,
		// 		success: function() {
		// 			uni.showToast({
		// 				title: '复制成功~',
		// 				icon: 'none',
		// 				duration: 1000
		// 			});
		// 		}
		// 	});
		// },
		//保存图片
		saveimg() {
			// #ifdef MP-WEIXIN
			////console.log('保存', uni.getStorageSync('url'));
			uni.getImageInfo({
				src: uni.getStorageSync('url'),
				success: function (image) {
					uni.saveImageToPhotosAlbum({
						filePath: image.path,
						success: function (res) {
							uni.showToast({
								title: '保存成功',
								icon: 'success'
							})
						},
						fail: function (err) {
							////console.log(err);
						}
					})
				}
			})
			// #endif
			// #ifdef APP-PLUS
			uni.saveImageToPhotosAlbum({
				filePath: this.sharedata.url,
				success: function (res) {
					////console.log(res,"URL")
					uni.showToast({
						title: "图片已保存",
						icon: "success",
						duration: 2000
					})
				},
				fail: function (res) {
					uni.showToast({
						title: "图片保存失败",
						icon: "success",
						duration: 2000
					})

				}
			});
			// #endif

		},
	}
};
</script>

<style lang="scss" scoped>
.content {
	height: 100vh;
	// height: 1240rpx;
	background-size: 100% 100% !important;
	background-repeat: no-repeat !important;

	.content_qrLink {
		width: 100%;
		padding-left: 450rpx;
		padding-top: 300rpx;
	}

	.mysharebtn {
		margin: 0;
		padding: 0;
		border: none;
		background-color: transparent;
	}

	.mysharebtn::after {
		border: none;
	}

	.share_box {
		width: 640rpx;
		min-height: 666rpx;
		background: #FFFFFF;
		border-radius: 50rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
		padding: 30rpx 0;

		.title {
			font-size: 38rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
		}

		.picurl {
			width: 254rpx;
			height: 320rpx;
			margin-top: 20rpx;
		}

		.name {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
		}

		.share_btn {
			width: 520rpx;
			margin: 0 auto;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				width: 238rpx;
				height: 60rpx;
				background: #666666;
				border-radius: 20rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
			}

			.right {
				width: 238rpx;
				height: 60rpx;
				background: #FDE253;
				border-radius: 20rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}
	}

	.footer {
		width: 670rpx;
		height: 205rpx;
		// margin: 0rpx auto;
		background: #FFFFFF;
		// box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.18);
		border-radius: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		bottom: 43rpx;
		left: 40rpx;

		// opacity: 0.8;
		.title {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 800;
			color: #333333;
			margin-top: 20rpx;
		}

		.icon {
			// width: 710rpx;
			width: 100%;
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;

			view {
				width: 160rpx;
				height: 160rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				box-sizing: border-box;

				image {
					width: 150rpx;
					height: 150rpx;
				}

				text {
					margin: 30rpx 0;
					font-size: 20rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #3D3D3D;
				}
			}
		}
	}

	.logo {
		width: 70%;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 66rpx;

		.logo_left {
			display: flex;
			align-items: center;

			image {
				width: 126rpx;
				height: 126rpx;
				border-radius: 10rpx;
			}

			text {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				margin-left: 20rpx;
			}
		}

		.logo_right {
			image {
				width: 109rpx;
				height: 109rpx;
			}
		}
	}

	.hezi {
		width: 263rpx;
		height: 68rpx;
		margin: 0 auto;
		margin-top: -20rpx;
		background: linear-gradient(180deg, #FBA88A 0%, #F44645 100%);
		border-radius: 34rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}

	.header {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 20rpx;
		margin-top: 28rpx;

		.title {
			font-size: 48rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.miaoshu {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
			margin-top: 20rpx;
		}
	}

	.section {
		width: 490rpx;
		height: 490rpx;
		margin: 0 auto;
		background: #F6F6F6;

		image {
			width: 432rpx;
			height: 426rpx;
		}
	}
}
</style>
